<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/views/common/includetag.jsp"%> 
<div class="clearfix"></div>

<link rel="stylesheet" type="text/css" href="${contextPath}/assets/jqueryplugin/jquery-treetable/jquery.treetable.css" >
<link rel="stylesheet" type="text/css" href="${contextPath}/assets/jqueryplugin/jquery-treetable/jquery.treetable.theme.default.css" >

<div class="row back-top-title">
	<div class="col-md-12">
		<span><spring:message code="app.resource.title" /></span>
	</div>
</div>

<form style="position:relative" id="splitPage" action="${pageContext.request.contextPath}/resource" method="POST" role="form" class="form-horizontal">
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-white">
				<div class="panel-body">
					<div class="row">
						 <div class="col-md-12 space20">
							<a href="#none" class="btn btn-primary btn-add">
								<i class="fa fa-plus"></i>
								<spring:message code="app.resource.action.add" />
							</a>
						 </div>
					</div>
					  
					<table class="table table-striped table-bordered table-hover table-full-width" id="dataTable">
				         <thead>
				             <tr>
				                 <th><spring:message code="app.resource.title.name" /></th>
				                 <th><spring:message code="app.resource.title.resourceType" /></th>
				                 <th><spring:message code="app.resource.title.resourceUrl" /></th>
				                 <th><spring:message code="app.resource.title.target" /></th>
				                 <th><spring:message code="app.resource.title.privilege" /></th>
				                 <th><spring:message code="app.resource.title.isShow" /></th>
				                 <th><spring:message code="app.common.action.operate" /></th>
				             </tr>
				         </thead>
				         <tbody>
				             <c:set var="resourceList" value="${PAGE_DATA}" scope="request" />
				             <c:import url="list-items.jsp" />
				         </tbody>
				     </table>
			    </div>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="${contextPath}/assets/jqueryplugin/jquery-treetable/jquery.treetable.js"></script>
<script type="text/javascript">
	$(function(){
       	$('.btn-add').click(function(){
       		location.href = '${contextPath}/resource/add';
       	});
       	
       	$('.btn-delete').click(function(){
       		var resourceId = $(this).parents('tr').attr('data-tt-id');
       		if(resourceId){
       			BootstrapDialog.confirm({
       				title: '<spring:message code="app.resource.title.delete" />',
       	            message: '<spring:message code="app.resource.title.delete.message" />',
       	            btnCancelLabel: '<spring:message code="app.common.action.cancel" />',
       	            btnOKLabel: '<spring:message code="app.common.action.confirm" />',
       	            callback: function(f){
       	            	if(f){
       	            		$.ajax({
       	        				type: 'POST',
       	        				url: '${contextPath}/resource/delete/exec',
       	        				data: {'id': resourceId},
       	        				success: function(result){
       	        					if(result){
       	        						var r = $.parseJSON(result);
       	        						if(r && r.resultCode == '000000'){
       	        							location.href = contextPath + '/resource';
       	        						}
       	        					}
       	        				}
       	        			});
       	            	}
       	            }
       			});
       		}
       	});
	});
</script>
<script type="text/javascript">
    $(function(){
    	//treeTable
    	$("#dataTable").treetable({
    		column: 0,
    		expandable: true,
    		stringExpand: '',
    		stringCollapse: '',
    		initialState: 'expanded'
    	}).show();
    });
</script>